using NodeCanvas.Variables;
using UnityEngine;

namespace NodeCanvas.Conditions
{
	[Name("Check Line Of Sight")]
	[Category("GameObject")]
	[AgentType(typeof(Transform))]
	[Description("Check of agent is in line of sight with target by doing a linecast and optionaly save the distance")]
	public class CheckLOS : ConditionTask
	{
		[RequiredField]
		public BBGameObject LosTarget;

		public Vector3 Offset;

		[BlackboardOnly]
		public BBFloat saveDistanceAs;

		private RaycastHit hit = default(RaycastHit);

		protected override string info
		{
			get
			{
				return "LOS with " + LosTarget.ToString();
			}
		}

		protected override bool OnCheck()
		{
			Transform transform = LosTarget.value.transform;
			if (Physics.Linecast(base.agent.transform.position + Offset, transform.position + Offset, out hit) && hit.collider != transform.GetComponent<Collider>())
			{
				saveDistanceAs.value = hit.distance;
				return false;
			}
			return true;
		}

		protected override void OnGizmosSelected()
		{
			if ((bool)base.agent && (bool)LosTarget.value)
			{
				Gizmos.DrawLine(base.agent.transform.position + Offset, LosTarget.value.transform.position + Offset);
			}
		}
	}
}
